package com.example.loginserver.domain;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public class SysUser implements UserDetails {

    private Long id;

    private String userName;

    private String password;

    private Integer loginStatus;

    private Collection<SimpleGrantedAuthority> authorities;

    public Long getId() {
        return id;
    }


    public SysUser(Long id, String userName, List<? extends Object> authorities) {
        this.id = id;
        this.userName = userName;
        this.authorities = authorities.stream().map(authority -> {
            return new SimpleGrantedAuthority(authority.toString());
        }).collect(Collectors.toList());
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public SysUser() {
        this.authorities = new LinkedList<>();
    }
}
